package com.aiju.support.mvp;

import android.os.Bundle;
import android.view.View;

/**
 * @author: 佐为
 * @date: 2017-02-14 14:27
 * @version: V1.0
 * @Description: 描述
 */
public abstract class BaseMvpActivity<V, T extends IPresenter<V>>
        extends BaseTitleActivity {

    public T mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPresenter = initPresenter();
        mPresenter.attach((V) this);
        setState(ViewState.LOAD);
    }

    @Override
    protected void onDestroy() {
        mPresenter.dettach();
        super.onDestroy();
    }

    public abstract T initPresenter();

    protected void setState(ViewState state, View.OnClickListener... listeners) {
        if (state == ViewState.LOAD) {
            mContentContainer.showLoadingView();
        } else if (state == ViewState.NOTDATA) {
            mContentContainer.showNodataView();
            for (View.OnClickListener listener : listeners) {
                mContentContainer.setOnNoDataRetryBtnClick(listener);
            }
        } else if (state == ViewState.NOTNET) {
            mContentContainer.showNoNetView();
            for (View.OnClickListener listener : listeners) {
                mContentContainer.setOnNoNetRetryBtnClick(listener);
            }
        } else {
            mContentContainer.showDataView();
        }
    }
}
